perm filename PUPW.C[11,HE] blob
sn#688211 filedate 1982-12-06 generic text, type T, neo UTF8
/* LINTLIBRARY */
/*
* pupwrite.c
*
* Pupwrite takes a buffer and sends it in a pup packet over
* a Pup channel.
*
* Jeffrey Mogul & Dan Kolkowitz 12-January-1981
* 26-January-1981
*
*/
#include <puppacket.h>
#include <pupconstants.h>
#include <pupstatus.h>
pupwrite(Pchan, Ptype, ID, buf,buflen)
struct PupChan *Pchan; /* channel to use */
uchar Ptype; /* Pup type */
ulong ID; /* Pup ID */
char *buf; /* data buffer */
int buflen; /* data buffer length */
{
struct EnPacket enpack; /* ether encapsulation */
int roundlen; /* length rounded up to even number */
roundlen = roundup(buflen); /* rounds UP to even number of bytes */
/*
* here we would switch on the Chan->transport to
* determine which lower-level encapsulation to use
* if there were any choice.
*/
enpack.Pup.PupLength = PUPACKOVER + buflen;
/* contains TRUE length of data */
enpack.Pup.PupType = Ptype;
enpack.Pup.PupTransport = 0; /* this has NOTHING to do with
* the tranport medium! */
enpack.Pup.PupID = makelong(ID);
PortPack(&Pchan->DstPort,&enpack.Pup.PupDst);
PortPack(&Pchan->SrcPort,&enpack.Pup.PupSrc);
if (buflen) /* dont move on zero length buffers */
bmove(buf,enpack.Pup.PupData, roundlen); /* put data in packet */
#ifdef PUP__NNSO /* non-standard byte order */
if (Pchan->mode&PCM_WFIXLAST) /* byte swap last word in buffer */
if (buflen&1) { /* if buffer length is odd */
enpack.Pup.PupData[buflen] = buf[buflen-1];
}
#else /* standard byte order - no trouble */
#endif
/* set checksum into first WORD following data */
if (Pchan->mode&PCM_WCHECKSUM) /* compute checksum */
*((ushort *) &enpack.Pup.PupData[roundlen]) =
checksum(&enpack.Pup,roundlen+PUPACKOVER-2);
else /* send null checksum */
*((short *) &enpack.Pup.PupData[roundlen]) = NOCKSUM;
return(enwrite(Pchan->ImmHost,PUP,Pchan->ofid,
&enpack,roundlen+PUPACKOVER));
}